<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>你瞅啥</title>
  <!--[if lt IE 9]>
  <script src="libs/html5shiv.min.js"></script>
  <script src="libs/respond.min.js"></script>
  <![endif]-->
  <script src="libs/jquery-1.12.1.min.js"></script>
  <script type="text/javascript" src="libs/handlebars.min.js"></script>
  <script type="text/javascript" src="libs/d3.v3.min.js"></script>  <!-- d3放在前面 -->
  <script type="text/javascript" src="libs/nv.d3.min.js"></script>  <!-- nv在后面 -->
  <link href="libs/bootstrap-3.3.6/css/nv.d3.min.css">
  <link href="libs/bootstrap-3.3.6/css/bootstrap.min.css" rel="stylesheet">
  <script src="libs/bootstrap-3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
  <div class="container">
    <div class="row">
      <div class="page-header"><h2><strong>你瞅瞅记账</strong></h2></div>
      <div class="col-md-8">
        <ul class="nav nav-pills">
          <li class=""><a href="index.html">首页</a></li>
          <li><a href="#">用户：<span id="account"></span></a></li>
          <li class=""><a href="shouru.html">添加新的收入</a></li>
          <li class=""><a href="zichu.html">添加新的支出</a></li>
          <li class=""><a href="jizhang.html">添加新的</a></li>
          <li class="active"><a href="chaxun.html">统计</a></li>
          <li class=""><a href="tongji.html">查询</a></li>
        </ul>
      </div>
    </div>
  </div>
  <div class="contrainer">
    <div class="row"><div class=cil-md-12><hr/></div> 
    </div>
  </div>
  <div class="container">
    <div class="row">
      <div class=col-md-6>  
      <div class="panel panel-warning">
          <div class="panel-heading"><h4>当月收入总和</h4></div>
          <div class="panel-body" id="text1"></div>
        </div>
	  </div>
      <div class=col-md-6> 
       <div class="panel panel-warning">
          <div class="panel-heading"><h4>当月收入总和</h4></div>
          <div class="panel-body" id="text2"></div>
        </div>
      </div>
   </div>
  </div>
<div class="container">
     <div class="row">
       <div class="col-md-12"> 
        <div class="panel panel-primary">
          <div class="panel-heading"><h4>每个类别收入总和、平均</h4></div>
          <div class="panel-body" id="list1"></div>
        </div> 
       </div>
    </div>
    <div class="row">
      <div class="col-md-12"> 
	    <div class="panel panel-success">
          <div class="panel-heading"><h4>每个类别支出总和、平均</h4></div>
          <div class="panel-body" id="list2"></div>
      </div>
    </div>
  </div>
</div>
<div class="container">
	<div class="row">
	  <div class="col-md-6" id="chart1">
	  <p class="text-center"><br>
	  <hr>
	  <strong>收入统计</strong>
	  <svg style="height:480px;width:100%"></svg>
	  <br>
	  
   </div>
   	<div class="col-md-6" id="chart2">
	  <p class="text-center"><br>
	  <hr>
	  <strong>支出统计</strong>
	  <svg style="height:480px;width:100%"></svg>
	  <br>
	  </div>
	 </div>
</div>
  <script id="template" type="text/x-handlebars-template">
  {{#each item}}
  <div class="panel panel-default col-md-3">
    <div class="panel-body"> 
     <dl>
       <dt>类别</dt><dd>{{kind}}</dd>
       <dt>总和</dt><dd>{{smoney}}</dd>
       <dt>平均值</dt><dd>{{amoney}}</dd>
    </dl>
   </div>
  </div>
 {{/each}}
</script>
</body>
<script type="text/javascript">
 $(function(){
	 $.getJSON('querynickname.action',function(res){
		 console.log(res);
		 $('#account').text(res.nickname);})
	   $.getJSON('querymonth.action',function(res){
		   console.log(res);
		   $('#text1').text(res.t1);
		   $('#text2').text(res.t2);     
	   })
	   $.getJSON('querykindsr.action',function(res){
		   console.log(res);
		   var date = {'item':res};
		   var t = Handlebars.compile($('#template').html());
		   $('#list1').html(t(date));
	   })
	    $.getJSON('querykindzc.action',function(res){
		   console.log(res);
		   var date = {'item':res};
		   var t = Handlebars.compile($('#template').html());
		   $('#list2').html(t(date));
	   })
	   $.getJSON('querykindsr.action',function(res){
		   nv.addGraph(function(){
			   var chart1 = nv.models.pieChart().x(function(d){
				   return d.kind
			   }).y(function(d){
				  return d.smoney
			   }).showLabels(true)
			   .labelType('percent');
			   d3.select("#chart1 svg")
			   .datum(res)
			   .transition().duration(350)
			   .call(chart1);
			   return chart1;
	     });
	   })
		   $.getJSON('querykindzc.action',function(res){
			   nv.addGraph(function(){
				   var chart2 = nv.models.pieChart().x(function(d){
					   return d.kind
				   }).y(function(d){
					  return d.smoney
				   }).showLabels(true)
				   .labelType('percent');
				   d3.select("#chart2 svg")
				   .datum(res)
				   .transition().duration(350)
				   .call(chart2);
				   return chart2;
		     })
	   })
	 })
 </script>
</html>